/*
 * StraightLine.java
 *
 * Created on 9 maj 2007, 19:03
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package pl.krakow.ae.knp.wikiboard.gui.drawables;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import pl.krakow.ae.knp.wikiboard.gui.board.Board;
import pl.krakow.ae.knp.wikiboard.utils.GraphicalUtils;

/**
 *
 *
 */

public class StraightLine extends Figure
{
    protected String name;
    private Line2D line;
    private Color color;
    
    /** Creates a new instance of Line */
    public StraightLine(Point2D startingPoint, Color color)
    {
        super();
        this.color = color;
        line = new Line2D.Double(startingPoint, startingPoint);
    }
    
    protected StraightLine(StraightLine sl)
    {
        super();
        this.line = (Line2D)sl.line.clone();
        this.color = GraphicalUtils.cloneColor(sl.color);
    }
    
    public void rotate()
    {
    }
    
    public void drag(MouseEvent event)
    {
        line.setLine(new Point2D.Double(line.getX1(), line.getY1()),
                event.getPoint());
    }
    
    public boolean contains(Point2D p)
    { return (line.ptLineDist(p) < 10); }
    
    public void draw(Graphics2D g, boolean dragged)
    {
        g.setXORMode(Board.getBgColor());
        if(!dragged)
            g.setPaintMode();
        g.setColor(color);
        g.draw(line);
        
        if (isSelected)
        {
            Graphics2D g2 = (Graphics2D)g.create();
            g2.setColor(Board.getSelectColor());
            g2.setStroke(new BasicStroke(STROKE_WIDTH));
            Rectangle2D rectangle = line.getBounds2D();
            g2.drawRect( (int)rectangle.getX() - SELECT_PADDING,
                    (int)rectangle.getY() - SELECT_PADDING,
                    (int)rectangle.getWidth() + 2*SELECT_PADDING,
                    (int)rectangle.getHeight() + 2*SELECT_PADDING);
            g2.dispose();
        }
    }
    
    public void move(double x, double y)
    { line.setLine(line.getX1()+x, line.getY1()+y, line.getX2()+x, line.getY2()+y); }
    
    public StraightLine clone()
    { return new StraightLine(this); }
    
    public void fill(Color c)
    {
    }
}
